<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
  }
  .funding-message-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .img{
   width: 150px;
   height: 100px;
   float: left;
   margin: 5px;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>操作充值记录</span>
    </div>
    <div class="line"></div>
    <funding-message-form
      class="funding-message-form"
      @on-success-valid="handleSubmit">
    </funding-message-form>
    <Table
      class="table"
      :columns="columns"
      :data="historyData"
      :loading="loading"
      border>
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import FundingMessageForm from '_c/funding-message-form'
import TablePage from '_c/table-page'
export default {
  components: {
    FundingMessageForm,
    TablePage
  },
  data () {
    return {
      page: 1,
      title: '财务管理操作充值记录',
      index: '',
      confirmData: {},
      playload: null,
      loading: true,
      rows: 20,
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 80,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '企业名称',
          key: 'company',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '电话',
          key: 'tel',
          minWidth: 120,
          align: 'center'
        },
        {
          title: '充值类型',
          key: 'type',
          minWidth: 130,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.type === 0 ? '佣金' : params.row.type === 1 ? '服务费' : '-')
          }
        },
        {
          title: '充值方式',
          key: 'paytype',
          minWidth: 150,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.paytype === 0 ? '银行卡' : params.row.paytype === 1 ? '微信' : params.row.paytype === 2 ? '支付宝' : '-')
          }
        },
        {
          title: '充值金额',
          key: 'price',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '充值日期',
          key: 'ctime',
          minWidth: 150,
          align: 'center'
        }
      ]
    }
  },
  computed: {
    ...mapState({
      fundingRecordList: state => state.fundingRecord.fundingRecordList,
      dataCount: state => state.fundingRecord.fundingRecordDataCount,
      historyData: state => state.fundingRecord.fundingRecordHistoryData,
      pageSize: state => state.fundingRecord.fundingRecordPageSize
    })
  },
  methods: {
    ...mapActions([
      'getFundingRecordList',
      'getFundingRecordCurrentRow',
      'changeFundingRecordPage',
      'changeFundingRecordPageSize'
    ]),
    handleSubmit (playload) {
      this.loading = true
      this.playload = playload
      this.getFundingRecordList(playload).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePage (index) {
      this.loading = true
      this.page = index
      this.changeFundingRecordPage(index)
      this.getFundingRecordList({
        page: index,
        rows: this.rows,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePageSize (value) {
      this.loading = true
      this.rows = value
      this.changeFundingRecordPageSize(value)
      this.changePage(this.page)
      this.getFundingRecordList({
        rows: value,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    }
  },
  created () {
    this.getFundingRecordList({}).then((res) => {
      if (res.data.state === '000') {
        this.loading = false
      }
    })
  }
}
</script>
